﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Game1942.Library.Background;

namespace Game1942.Library.FlightPlans
{
    public class CirclesStrategy : FlightPlan
    {
        private double radius = 200;
        private double angle;
        private readonly int centralX = Background.Background.Instance.GetDimension().X / 2;
        private readonly int centralY = Background.Background.Instance.GetDimension().Y / 2;
        private bool calculateRadio = false;

        
        public CirclesStrategy(int speed): base(speed)
        {
        }

        public override Point GetNext()     //Usar Speed
        {
            if (!calculateRadio)
            {
                CalculateRadio();
                calculateRadio = true;
            }
            double deltaX = actualPosition.X - centralX;
            double deltaY = centralY - actualPosition.Y;

            angle = Math.Atan2(deltaY, deltaX) - (2*Math.PI/180);


            actualPosition.X = (int)(radius * Math.Cos(angle)) + centralX;
            actualPosition.Y = centralY - (int)(radius * Math.Sin(angle));
            return new Point(actualPosition.X, actualPosition.Y);

        }

        private Double CalculateRadio()
        {
            return Math.Sqrt(Math.Pow(actualPosition.X - centralX, 2) +
                      Math.Pow(actualPosition.Y - centralY, 2));
        }
    }
}
